version 13
#delimit;
clear all;
set more off;
capture log close;


global strformat "%8.3f";

capture program drop sig_p;
program sig_p;
   args obj_var point_est_var point_sd_var p_val row_id_var row_num;
   local point_est `point_est_var';
   local point_sd `point_sd_var';
   if `p_val' > 0.1 {;
      replace `obj_var' = string(`point_est', "$strformat") if `row_id_var' == `row_num';
      };
   if `p_val' > 0.05 & `p_val' <= 0.1  {;
      replace `obj_var' = string(`point_est', "$strformat")+"*" if `row_id_var' == `row_num';
      };
   if `p_val' > 0.01 & `p_val' <= 0.05  {;
      replace `obj_var' = string(`point_est', "$strformat")+"**" if `row_id_var' == `row_num';
      };
   if `p_val' <= 0.01 {;
      replace `obj_var' = string(`point_est', "$strformat")+"***" if `row_id_var' == `row_num';
      };
   replace `obj_var' = "<" + string(`point_sd', "$strformat") + ">" + " " if `row_id_var' == `row_num' + 1;
   end;


*enter directory name here;

use "$dir/ReStat_children.dta", clear;
		
	
global fu_child_controls_cm
	"control_fu_child_age control_fu_female
	missing_fu_child_age missing_fu_female";
		
global fu_hh_controls_cm
	"control_fu_adults control_fu_hh_head_edu control_fu_hh_head_occ_farmer 
	control_fu_total_land control_fu_household_size
	missing_fu_adults missing_fu_hh_head_edu missing_fu_hh_head_occ_farmer 
	missing_fu_total_land missing_fu_household_size";



generate row_num = _n;



forvalues i=0/25 {;
	generate col`i' = "";
};

local row = 4;	

sort row_num;
order col0-col25;


generate fu_future_job_table = 1 if
	fu_future_job == "Civil servant" |
	fu_future_job == "Doctor" |
	fu_future_job == "Employed in Private enterprise" |
	fu_future_job == "Engineer" |
	fu_future_job == "Farmer" |
	fu_future_job == "Housewife" |
	fu_future_job == "Laborer" |
	fu_future_job == "Landlord" |
	fu_future_job == "Lawyer" |
	fu_future_job == "Police/army/security" |
	fu_future_job == "Raise livestock" |
	fu_future_job == "Teacher";
	
levelsof fu_future_job if fu_future_job_table == 1, local(fu_future_job);

foreach f of local fu_future_job {;
	
	replace col0 = "`f'" if row_num == `row';
	
	generate fu_future_job_x = 0 if fu_future_job ~= "";
	replace fu_future_job_x = 1 if fu_future_job == "`f'";
	
	su fu_future_job_x if fu_child_level == 1 & fu_young_child == 1 &
		pooled_treatment == 0 [aw=hh_weight];
	replace col2 = string(r(mean), "$strformat") if row_num == `row';
	regress fu_future_job_x pooled_treatment if fu_child_level == 1 & fu_young_child == 1
		[pw=hh_weight], cluster(villcode);
	test pooled_treatment;
	sig_p col3 _b[pooled_treatment] _se[pooled_treatment] r(p) row_num `row';

	regress fu_future_job_x fu_female pooled_treatment treatment_female
		if fu_child_level == 1 & fu_young_child == 1 [pw=hh_weight], cluster(villcode);
	test fu_female;	
	sig_p col5 _b[fu_female] _se[fu_female] r(p) row_num `row';
	test pooled_treatment;	
	sig_p col6 _b[pooled_treatment] _se[pooled_treatment] r(p) row_num `row';
	test treatment_female;	
	sig_p col7 _b[treatment_female] _se[treatment_female] r(p) row_num `row';

	
	drop fu_future_job_x;
	
	local row = `row' + 2;
	
};	

local row = `row' + 1;






replace col0 = "ideal marriage age" if row_num == `row';	
su fu_ideal_marriage_age if fu_child_level == 1 & fu_young_child == 1 &
	pooled_treatment == 0 [aw=hh_weight];
replace col2 = string(r(mean), "$strformat") if row_num == `row';
regress fu_ideal_marriage_age pooled_treatment if fu_child_level == 1 & fu_young_child == 1
	[pw=hh_weight], cluster(villcode);
test pooled_treatment;
sig_p col3 _b[pooled_treatment] _se[pooled_treatment] r(p) row_num `row';

regress fu_ideal_marriage_age fu_female pooled_treatment treatment_female
	if fu_child_level == 1 & fu_young_child == 1 [pw=hh_weight], cluster(villcode);
test fu_female;	
sig_p col5 _b[fu_female] _se[fu_female] r(p) row_num `row';
test pooled_treatment;	
sig_p col6 _b[pooled_treatment] _se[pooled_treatment] r(p) row_num `row';
test treatment_female;	
sig_p col7 _b[treatment_female] _se[treatment_female] r(p) row_num `row';


local row = `row' + 2;

replace col0 = "ideal education" if row_num == `row';	
su fu_ideal_edu_qualif if fu_child_level == 1 & fu_young_child == 1 &
	pooled_treatment == 0 [aw=hh_weight];
replace col2 = string(r(mean), "$strformat") if row_num == `row';
regress fu_ideal_edu_qualif pooled_treatment if fu_child_level == 1 & fu_young_child == 1
	[pw=hh_weight], cluster(villcode);
test pooled_treatment;
sig_p col3 _b[pooled_treatment] _se[pooled_treatment] r(p) row_num `row';

regress fu_ideal_edu_qualif fu_female pooled_treatment treatment_female
	if fu_child_level == 1 & fu_young_child == 1 [pw=hh_weight], cluster(villcode);
test fu_female;	
sig_p col5 _b[fu_female] _se[fu_female] r(p) row_num `row';
test pooled_treatment;	
sig_p col6 _b[pooled_treatment] _se[pooled_treatment] r(p) row_num `row';
test treatment_female;	
sig_p col7 _b[treatment_female] _se[treatment_female] r(p) row_num `row';

local row = `row' + 6;


outsheet col0-col7 using "$dir/Table 7 Child Aspirations.csv" if
	row_num < `row', comma replace;	
